package com.ganwei.mybatisplus.config.util;

import lombok.Getter;
import lombok.Setter;

import java.util.List;

/**
 * 通用分页数据结果集
 * @author gw
 */
public class PageData<T> {

    public static class Page {
        @Setter
        @Getter
        private int pageNum;

        @Setter
        @Getter
        private int pageSize;

        @Setter
        @Getter
        private int totalRecord;

        @Setter
        @Getter
        private int totalPage;

        void setTotalPage() {
            totalPage = totalRecord / pageSize;
            if(totalRecord % pageSize > 0) {
                totalPage++;
            }
        }
    }

    @Getter
    @Setter
    private List<T> list;

    public PageData(List<T> list) {
        this.list = list;
        pageInfo = new Page();
    }

    @Setter
    @Getter
    private Page pageInfo;

    public void setPageInfo(int pageNum, int pageSize, int totalRecord) {
        pageInfo.setPageNum(pageNum);
        pageInfo.setPageSize(pageSize);
        pageInfo.setTotalRecord(totalRecord);
        pageInfo.setTotalPage();
    }
}
